#include <iostream>
#include <vector>
#include <unordered_map>
#include <cmath>
#include <string>
#include <sstream>

bool prost(int a) {
    if (a == 1) {
        return false;
    }
    for (int i = 2; i <= static_cast<int>(std::sqrt(a)); ++i) {
        if (a % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string input;
    std::getline(std::cin, input);
    std::istringstream iss(input);
    std::vector<std::string> a;
    std::string word;
    while (iss >> word) {
        a.push_back(word);
    }

    std::unordered_map<std::string, std::string> b = {
        {"zero", "0"}, {"one", "1"}, {"two", "2"}, {"three", "3"}, {"four", "4"},
        {"five", "5"}, {"six", "6"}, {"seven", "7"}, {"eight", "8"}, {"nine", "9"}
    };

    std::string c = "";
    bool f = false;
    for (const auto& i : a) {
        if (i.find_first_of("123456789") != std::string::npos) {
            f = true;
            break;
        }
    }

    if (f) {
        std::cout << "Wrong input" << std::endl;
    } else {
        for (const auto& j : a) {
            c += b[j];
        }
        int c_int = std::stoi(c);
        int d1 = 0, d2 = 0;
        int k = c_int;
        while (!prost(k)) {
            k++;
            d1++;
        }
        int k2 = c_int;
        while (!prost(k2)) {
            k2--;
            d2++;
        }
        if (d1 <= d2) {
            std::cout << k << std::endl;
        } else {
            std::cout << k2 << std::endl;
        }
    }

    return 0;
}

